package com.guess.lolguessing.controller;


import com.guess.lolguessing.domain.po.Matches;
import com.guess.lolguessing.domain.vo.MatchDetailsVO;
import com.guess.lolguessing.result.Result;
import com.guess.lolguessing.service.IMatchesService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-10-09
 */
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
@CrossOrigin(origins = {"http://localhost:8080", "http://172.24.0.1:8080"}) // 允许来自该源的请求
public class MatchesController {

    private  final IMatchesService matchesService;
    // 获取比赛
    @GetMapping("/match")
    public List<Matches> getMatches() {
        return matchesService.getMatches();
    }

    // 获取比赛的详细信息
    @GetMapping("/matches/{matchId}")
    public Result<MatchDetailsVO> getMatchDetails(@PathVariable Long matchId) {
        // 构造比赛信息和队伍信息
        MatchDetailsVO matchDetails = matchesService.getMatchDetails(matchId);

        return Result.success(matchDetails);
    }
}
